package com.jmoney.luckeylink.controller;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JOptionPane;

import com.jmoney.luckeylink.util.DataBaseUtil;

public class LekeU_Captcha_Controller {
	
	private static ResultSet rs;
	private static Statement sm;
	private static Connection con;
	
	//根据数据版本连接对应数据库
    public static String GetSqlResult(String DataVersion, String id, String FieldName)throws IOException{
      
	    String sql = "select su.phone as phone,su.role_id as roleId,sr.role_desc as roleName,su.id as salesId,su.user_name as userName,su.photo_name as photoName "
	    		+ "from dafy_sales.sys_user_list su "
	    		+ "inner join  dafy_sales.sys_role_list sr on sr.role_id=su.role_id "
	    		+ "WHERE su.id="+id+" and su.ROLE_ID = sr.ROLE_ID";
	    try{
	    	DataBaseUtil.checkConnection_Oracle(DataVersion);
	        rs = sm.executeQuery(sql);
	        while(rs.next()){
	            String pa = rs.getString(FieldName);
	            System.out.println(pa);
	            return pa; 
	        }
	    }catch(SQLException e){
	        e.printStackTrace();
	    }finally{
	    	DataBaseUtil.close(sm,rs);
	    }
		return null;   
	}

	//对比用户名和密码是不匹配
	public static boolean logincompare1(String DataVersion,String username, String password){
	    boolean m = false;
	    String sql = "select PASSWORD from dafy_sales.sys_user_list where id="+ username +"";
	    try{
	    	DataBaseUtil.checkConnection_Oracle(DataVersion);
	    	sm = con.createStatement();
	        rs = sm.executeQuery(sql);
	        if(rs.next()){
	            String pa = rs.getString(1);
	            System.out.println(pa + " " + password);
	            if(pa.equals(password)){
	                m = true;
	            }else {
	                   JOptionPane.showMessageDialog(null, "密码错误！");
	            }
	        }else {
	               JOptionPane.showMessageDialog(null, "用户名不存在！");
	        }
	        DataBaseUtil.close(sm,rs);   
	    }catch(SQLException e){
	        e.printStackTrace();
	    }
	    return m;
	}
}
